#!/bin/csh

if ( ! -e /tmp/$USER ) then
   mkdir  /tmp/$USER
endif
set TMPDIR=/tmp/$USER

# The necessary arguments:
set startdate = 2002-08-25+12     # YYYY-MM-DD+HH
set ndates = 10
set itimint = 6

### If you uncomment this line, also uncomment the line containing
### "rcp" later in the script
#set Host = username@host.domain:/local_directory


###############################################################################
######################                         ################################
######################  END USER MODIFICATION  ################################
######################                         ################################
###############################################################################

cd $TMPDIR
cp ~mesouser/MM5V3/Util/geth_newdate .
cp ~mesouser/MM5V3/Util/newdate.awpr .

# Set up the list "mdate".  "mdate" will hold all the times we 
# need to get.

set num = 0
set idth = -$itimint
set mdate = ( )
while ( $num < $ndates )
   @ idth = $idth + $itimint
   @ num ++
   set ndate = `./geth_newdate ${startdate} ${idth}`
   set mdate = ( ${mdate} ${ndate} )
end

echo "mdate = $mdate"

# Construct the dates as they appear in the upper-air archive titles.
# Use awk (nawk) to get the actual MSS filenames from the archive lists.


foreach ndate ( $mdate ) 

   set YY = `echo $ndate | cut -b 3-4`
   set Mm = `echo $ndate | cut -b 6-7`
   set Dd = `echo $ndate | cut -b 9-10`
   set HH = `echo $ndate | cut -b 12-13`

   echo $YY $Mm $Dd $HH

# Get the final analysis data files.

   set local = fnl_${YY}${Mm}${Dd}_${HH}_00
   if ( ! -e $local ) then 
      echo "msread $local /DSS/DS083.2/data/${local}"
      msread $local /DSS/DS083.2/data/${local}
#      rcp $local ${Host}
   endif

end

rm geth_newdate 
rm newdate.awpr

echo "#####################################################"
echo " "
echo " The data required to run pregrid will be saved  "
echo " as fnl_YYMMDD_HH_00"
echo " "
echo "#####################################################"

echo "DONE"

exit
